
var _name = document.querySelectorAll("input")[0];
var pass = document.querySelectorAll("input")[1];
var btn = document.querySelector("button");
var _text = document.querySelector("span");

btn.addEventListener("click" , function(){
    // 1、创建ajax对象
    let xhr = new XMLHttpRequest();

    // 2、设定open();
    xhr.open("post" , "http://localhost:8888/users/login");

    xhr.setRequestHeader("content-type" , "application/x-www-form-urlencoded");

    // 3、设定send()
    xhr.send(`username=${_name.value}&password=${pass.value}`);

    // 4、接受请求结果
    xhr.onload = function(){
        let result = JSON.parse(xhr.response);
        console.log(result);
        if(result.code === 1){
            _text.innerHTML = `${result.message}${result.tips}`;
        }
    }
})
